草庐IT

strings 包

全部标签

string - Swift 如何检查多个字符串条件的变量

目前我正在检查字典中的键是否包含特定的字符串值:ifdict["eventCode"]=="OFF"||dict["eventCode"]=="DHD"||dict["eventCode"]=="SBY"{//dosomething}elseifdict["eventCode"]=="DHT"||dict["eventCode"]=="SLV"||dict["eventCode"]=="CLV"{//dosomethingelse}可能值的列表大约有10个,if语句有效但冗长且容易出现类型错误。折射这种“if语句”的最佳方法是什么? 最佳答案

LeetCode #1234 Replace the Substring for Balanced String 替换子串得到平衡字符串

1234ReplacetheSubstringforBalancedString替换子串得到平衡字符串Description:Youaregivenastringsoflengthncontainingonlyfourkindsofcharacters:'Q','W','E',and'R'.Astringissaidtobebalancedifeachofitscharactersappearsn/4timeswherenisthelengthofthestring.Returntheminimumlengthofthesubstringthatcanbereplacedwithanyothe

ios - 将 TimeInterval 转换为字符串 <del>String To Time Interval</del>

我有一个TimeInterval我必须将它变成一个String以便它可以添加到从AppleWatch传递的Dictionary通过WatchConnectivity连接到iPhone。现在我在iPhone上有了String,我需要把它变回TimeInterval,但我似乎不能弄清楚这一点。(我需要在显示锻炼持续时间的UILabel中显示它。)有什么想法吗?例如观看:00:15:15(时、分、秒)变成“915.012948989868”letmyDouble=computeDurationOfWorkout(withEvents:hkWorkout?.workoutEvents,star

ios - 参数类型 'String' 不符合预期类型 'Sequence'

我正在为ios开发一个应用程序,我正在尝试获取我定义的字典成员的每个字母:varMorse=["a":"01","b":"1000","c":"1010","d":"100","e":"0","f":"0010","g":"110","h":"0000","i":"00","j":"0111","k":"101","l":"0100","m":"11","n":"10","o":"111","p":"0110","q":"1101","r":"010","s":"000","t":"1","u":"001","v":"0001","w":"011","x":"1001","y":"10

json - 无法使用类型为 'String' 的索引为类型 [Dictionary<String, Any>] 的值下标

我正在尝试读取从Alamofire返回给我的一些数据,但在尝试导航JSON时遇到此错误。这是我的代码:Alamofire.request(requestURL).responseJSON{responseinifletJSON=response.result.valueas?[Dictionary]{ifletreviews=JSON["reviews"]as?[Dictionary]{//Itsgivingmetheerrorhereforreviewinreviews{print(review["description"])}}}}我得到的错误:Cannotsubscriptava

string - 如何在 swift 中使用 if let 和另一个语句?

如果既要分配一个字符串又要检查它在Swift中是否为空。ifletalternative3Text=attributes.stringForKey("choiceThree")&&alternative3Text!=""{//dostuffwithalternative3Text}这在Swift中可行吗,还是我必须执行嵌套的if语句? 最佳答案 更新:从Swift3(Xcode8)开始,附加子句是用逗号分隔,而不是where:ifletalternative3Text=attributes.string(forKey:"choice

string - 如何将函数添加到 Swift 作为 String 的扩展以简化使用

我有一个函数编码为:funcdeleteEnclosedString(s:String,startStrings1:String,endStrings2:String)->String{}我想创建一个类,它被子类化为String,我在其中定义了一个函数并按如下方式使用它:varmyString="A[typical]string"myString.deleteEnclosedString(startString:"[",endString:"]") 最佳答案 您可以通过以下方式进行:extensionString{funcdelet

string - Swift 通过字符串调用类函数或属性

我有这门课classFoo{publicclassfuncbarFunction(){}publicclassfuncbarFunction2(){}publicclassfuncbarFunction3(){}}目前我有一个switch函数来确定调用哪个bar方法switchbar{case"bar":Foo.barFunction(param:Double)case"bar2":Foo.barFunction2(param:Double)case"bar3":Foo.barFunction3(param:Double)default:return}如果我可以通过连接字符串来组成ba

ios - 无法使用类型为 'enumerate' 的参数列表调用 '(String)'

当我遵循NeilNorth的iOSSwift游戏教程时,出现错误“无法使用类型为‘(String)’的参数列表调用‘enumerate’”。这与1.2中的某种旧方法有关吗?有什么想法吗?convenienceinit(atlasName:String,tileSize:CGSize,tileCodes:[String]){self.init(tileSize:tileSize,gridSize:CGSize(width:tileCodes[0].characters.count,height:tileCodes.count))atlas=SKTextureAtlas(named:atl

swift - 类型 'Observable<String>' 的值没有成员 'bind'

我试图将ViewModel中的字符串值绑定(bind)到我的ViewController中的标签,但出现以下错误:Valueoftype'Observable'hasnomember'bind'MycodeforbindinginViewController:self.viewModel.myNum.map({$0}).bind(to:serialNumberLabel.rx.text)myNum在vi​​ewModel中定义如下:varmyNum:Observable不,我这里有两个问题:1.ViewController中的上述错误2.在ViewModel中初始化myNum我尝试按照